//
//  FounctionCollectionCell.m
//  EducationAdminClient
//
//  Created by KWSD on 15/11/26.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

#import "FounctionCollectionCell.h"
#import "Masonry.h"
#import "UIColor+CL.h"
#import "EducationAdminClient_URL.h"
//#import "UIStyle.h"

@implementation FounctionCollectionCell

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
        self.contentView.backgroundColor =[UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1];
    }
    return self;
}

-(void)creatUI{
    
    _v= [[UIView alloc]init];
    [self.contentView addSubview:_v];
    _v.backgroundColor =[UIColor whiteColor];
    
    
//#ifdef Main
    
    if([getUIStyle() isEqualToString:STYLE0]){
    [_v mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.contentView.mas_top);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
    
    _lineTop = [[UIView alloc] init];
    _lineButtom = [[UIView alloc] init];
    _lineRight = [[UIView alloc] init];
    _lineLeft = [[UIView alloc] init];
    
    
    _lineTop.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    _lineButtom.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    _lineRight.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    _lineLeft.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    
    
    _NumberLa = [[UILabel alloc] init];
    [_v addSubview:_NumberLa];
    [_v addSubview:_lineTop];
    [_v addSubview:_lineButtom];
    [_v addSubview:_lineRight];
    [_v addSubview:_lineLeft];
    
    
    [_lineTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(1));
        make.top.equalTo(_v.mas_top);
        make.left.equalTo(_v.mas_left);
        make.right.equalTo(_v.mas_right);
    }];
    [_lineButtom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(1));
        make.bottom.equalTo(_v.mas_bottom);
        make.left.equalTo(_v.mas_left);
        make.right.equalTo(_v.mas_right);
    }];
    [_lineLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(0.5));
        make.top.equalTo(_v.mas_top);
        make.left.equalTo(_v.mas_left);
        make.bottom.equalTo(_v.mas_bottom);
    }];
    [_lineRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(1));
        make.bottom.equalTo(_v.mas_bottom);
        make.top.equalTo(_v.mas_top);
        make.right.equalTo(_v.mas_right);
    }];
    
    _titleImg =[[UIImageView alloc]init];
    [_v addSubview:_titleImg];
    [_titleImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_v.mas_centerY);
        make.left.equalTo(_v.mas_left).offset(40/2);
        make.width.equalTo(@(68/2));
        make.height.equalTo(@(70/2));
        //        make.width.equalTo(@(30));
        //        make.height.equalTo(@(30));
    }];
    
    //    _titleImg2 =[[UIImageView alloc]init];
    //
    //
    //    [_v addSubview:_titleImg2];
    //    [_titleImg2 mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.centerX.equalTo(_v.mas_centerX);
    //        make.centerY.equalTo(_v.mas_centerY);
    //        make.width.equalTo(@(50));
    //        make.height.equalTo(@(10));
    //    }];
    //    _titleImg2.image = [UIImage imageNamed:@"123"];
    //    _titleImg2.hidden = YES;
    _titleLa = [[UILabel alloc]init];
    //    [_titleLa sizeToFit];
    [_v addSubview:_titleLa];
    [_titleLa mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.centerX.equalTo(_titleImg.mas_centerX);
        make.bottom.equalTo(_NumberLa.mas_top).offset(-16/2);
        make.left.equalTo(_titleImg.mas_right).offset(18/2);
        make.right.equalTo(_v.mas_right).offset(-5);
        //        make.right.equalTo(_v.mas_right);
    }];
    
    _titleLa.numberOfLines = 2;
    [_titleLa sizeToFit];
    _titleLa.lineBreakMode = NSLineBreakByTruncatingTail;
    
    _titleLa.font = [UIFont systemFontOfSize:26/2];
    _titleLa.text = @"";
    _titleLa.textColor = [UIColor colorWithHex:0x787878];
    
    
    
    
    [_NumberLa mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.centerX.equalTo(_titleImg.mas_centerX);
        make.top.equalTo(_v.mas_top).offset(96/2);
        make.left.equalTo(_titleLa.mas_left);
        
        
        //        make.right.equalTo(_v.mas_right);
    }];
    _NumberLa.numberOfLines = 1;
    [_NumberLa sizeToFit];
    _NumberLa.lineBreakMode = NSLineBreakByTruncatingTail;
    
    _NumberLa.font = [UIFont systemFontOfSize:32/2];
    _NumberLa.text = @"";
    _NumberLa.textColor = [UIColor colorWithHex:0x333333];
    }else{
    

//#elif Student
    [_v mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.contentView.mas_top);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
    _NumberLa = [[UILabel alloc] init];
    [_v addSubview:_NumberLa];
    _lineTop = [[UIView alloc] init];
    _lineButtom = [[UIView alloc] init];
    _lineRight = [[UIView alloc] init];
    _lineLeft = [[UIView alloc] init];
    
    
    _lineTop.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    _lineButtom.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    _lineRight.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    _lineLeft.backgroundColor = [UIColor colorWithHex:0xdcdcdc];
    
    
    
    [_v addSubview:_lineTop];
    [_v addSubview:_lineButtom];
    [_v addSubview:_lineRight];
    [_v addSubview:_lineLeft];
    
    
    [_lineTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(1));
        make.top.equalTo(_v.mas_top);
        make.left.equalTo(_v.mas_left);
        make.right.equalTo(_v.mas_right);
    }];
    [_lineButtom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(1));
        make.bottom.equalTo(_v.mas_bottom);
        make.left.equalTo(_v.mas_left);
        make.right.equalTo(_v.mas_right);
    }];
    [_lineLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(0.5));
        make.top.equalTo(_v.mas_top);
        make.left.equalTo(_v.mas_left);
        make.bottom.equalTo(_v.mas_bottom);
    }];
    [_lineRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(1));
        make.bottom.equalTo(_v.mas_bottom);
        make.top.equalTo(_v.mas_top);
        make.right.equalTo(_v.mas_right);
    }];
    
    _titleImg =[[UIImageView alloc]init];
    [_v addSubview:_titleImg];
    [_titleImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_v.mas_top).offset(36/2);
        make.centerY.equalTo(_v.mas_centerY);
        make.left.equalTo(_v.mas_left).offset(40/2);
        make.width.equalTo(@(68/2));
        make.height.equalTo(@(70/2));
        //        make.width.equalTo(@(30));
        //        make.height.equalTo(@(30));
    }];
    
//    _titleImg2 =[[UIImageView alloc]init];
//    
//    
//    [_v addSubview:_titleImg2];
//    [_titleImg2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(_v.mas_centerX);
//        make.centerY.equalTo(_v.mas_centerY);
//        make.width.equalTo(@(50));
//        make.height.equalTo(@(10));
//    }];
//    _titleImg2.image = [UIImage imageNamed:@"123"];
//    _titleImg2.hidden = YES;
    _titleLa = [[UILabel alloc]init];
    //    [_titleLa sizeToFit];
    [_v addSubview:_titleLa];
    [_titleLa mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(_titleImg.mas_centerX);
//        make.top.equalTo(_v.mas_top).offset(20/2);
        make.bottom.equalTo(_NumberLa.mas_top).offset(-16/2);
        make.left.equalTo(_titleImg.mas_right).offset(18/2);
        make.right.equalTo(_v.mas_right).offset(-5);
//        make.right.equalTo(_v.mas_right);
    }];
    
    _titleLa.numberOfLines = 2;
    [_titleLa sizeToFit];
    _titleLa.lineBreakMode = NSLineBreakByTruncatingTail;
    
    _titleLa.font = [UIFont systemFontOfSize:26/2];
    _titleLa.text = @"";
    _titleLa.textColor = [UIColor colorWithHex:0x787878];
    
    
//        UILabel *lb = [[UILabel alloc] init];
//        [_v addSubview:lb];
//        lb.backgroundColor = [UIColor redColor];
//        [lb mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(_v.mas_top);
//            make.height.equalTo(@(96/2));
//            make.width.equalTo(@(1));
//        }];
    
    [_NumberLa mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.centerX.equalTo(_titleImg.mas_centerX);
        make.top.equalTo(_v.mas_top).offset(96/2);
        make.left.equalTo(_titleLa.mas_left);
        
        
        
    }];
    _NumberLa.numberOfLines = 1;
    [_NumberLa sizeToFit];
    _NumberLa.lineBreakMode = NSLineBreakByTruncatingTail;
    
    _NumberLa.font = [UIFont systemFontOfSize:32/2];
    _NumberLa.text = @"";
    _NumberLa.textColor = [UIColor colorWithHex:0x333333];
    }
    
//#endif
    
    
    
}

-(void)changeLine:(NSIndexPath *)indexPath{
    NSLog(@"%zd",indexPath.row);
    
    if (indexPath.row%2 == 0) {
        [_titleImg mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_v.mas_left).offset(40/2);
        }];
        [_titleLa mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_v.mas_right).offset(-10/2);
        }];
    }else{
        [_titleLa mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_v.mas_right).offset(-30/2);
        }];
        [_titleImg mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_v.mas_left).offset(20/2);
        }];
    }
    
    
    if (indexPath.row%2 == 0) {
        if (indexPath.row == 0) {
            [_lineTop mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(_v.mas_right);
                make.left.equalTo(_v.mas_left);
            }];
            [_lineRight mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_v.mas_top).offset(4);
                
            }];
            [_lineButtom mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(_v.mas_left).offset(30/2);
                make.right.equalTo(_v.mas_right);
            }];
            _lineTop.hidden = NO;
        }else{
            _lineTop.hidden = YES;
            [_lineRight mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_v.mas_top);
            }];
            [_lineButtom mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(_v.mas_left).offset(30/2);
                make.right.equalTo(_v.mas_right);
            }];
            [_lineTop mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(_v.mas_left).offset(30/2);
            }];
        }
        
        
        
        
    }else{
        if (indexPath.row == 1) {
            [_lineTop mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(_v.mas_right);
                make.left.equalTo(_v.mas_left);
            }];
            [_lineRight mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_v.mas_top).offset(4);
            }];
            [_lineButtom mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(_v.mas_right).offset(-30/2);
                make.left.equalTo(_v.mas_left);
            }];
            _lineTop.hidden = NO;
        }else{
            _lineTop.hidden = YES;
            [_lineRight mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_v.mas_top);
                
            }];
            [_lineButtom mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(_v.mas_right).offset(-30/2);
                make.left.equalTo(_v.mas_left);
            }];
            [_lineTop mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(_v.mas_right).offset(-30/2);
            }];
        }
        
    }
    _lineLeft.hidden = YES;
    
    
}

-(void)changeRect:(BOOL)isChange{
    if(isChange){
        _titleImg2.hidden = NO;
        _titleImg.hidden = YES;
        _titleLa.hidden = YES;
    }else{
        _titleImg2.hidden = YES;
        _titleImg.hidden = NO;
        _titleLa.hidden = NO;
    }
}

@end
